package com.kcloud.commons.entity.control;

import com.kcloud.commons.entity.core.StandardAttribute;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 属性集
 */
@Data
@NoArgsConstructor
public class AttributeGroup implements StandardAttribute {

    /**
     * 属性集类型：主集
     */
    public static final String GROUP_TYPE_MAIN = "main";
    /**
     * 属性集类型：子集
     */
    public static final String GROUP_TYPE_CHILD = "part";
    /**
     * 属性集编码规则，主集就是主表的实体对象名称，子集就是子表的实体对象名称，不区分大小写
     */
    private String groupCode;
    private String groupName; //属性集名称
    private String groupType; // 属性集类型
    private List<Attribute> attributes; // 属性清单
    private Boolean checked = false;

    public AttributeGroup(String groupCode, String groupName, String groupType) {
        this.groupCode = groupCode;
        this.groupName = groupName;
        this.groupType = groupType;
    }

    public void addAttribute(Attribute attribute) {
        if(attributes == null) {
            attributes = new ArrayList<>();
        }
        attributes.add(attribute);
    }
    @Override
    public void setId(String id) {
        this.groupCode = id;
    }

    @Override
    public String getId() {
        return this.groupCode;
    }

    @Override
    public void setTitle(String title) {
        this.groupName = title;
    }

    @Override
    public void setType(String type) {
        this.groupType = type;
    }

    @Override
    public String getTitle() {
        return this.groupName;
    }

    @Override
    public String getType() {
        return this.groupType;
    }
}